'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    await queryInterface.createTable('users', {
      id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
      },
      username: {
        type: Sequelize.STRING(50),
        allowNull: false,
        unique: true,
        comment: '用户名',
      },
      email: {
        type: Sequelize.STRING(100),
        allowNull: false,
        unique: true,
        comment: '邮箱',
      },
      password: {
        type: Sequelize.STRING(255),
        allowNull: false,
        comment: '密码',
      },
      nickname: {
        type: Sequelize.STRING(50),
        allowNull: true,
        comment: '昵称',
      },
      avatar: {
        type: Sequelize.STRING(255),
        allowNull: true,
        comment: '头像URL',
      },
      gender: {
        type: Sequelize.ENUM('male', 'female', 'other'),
        allowNull: true,
        comment: '性别',
      },
      birthday: {
        type: Sequelize.DATE,
        allowNull: true,
        comment: '生日',
      },
      height: {
        type: Sequelize.INTEGER,
        allowNull: true,
        comment: '身高(cm)',
      },
      weight: {
        type: Sequelize.INTEGER,
        allowNull: true,
        comment: '体重(kg)',
      },
      bio: {
        type: Sequelize.TEXT,
        allowNull: true,
        comment: '个人简介',
      },
      status: {
        type: Sequelize.ENUM('active', 'inactive', 'banned'),
        defaultValue: 'active',
        comment: '用户状态',
      },
      last_login_at: {
        type: Sequelize.DATE,
        allowNull: true,
        comment: '最后登录时间',
      },
      created_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.NOW,
      },
      updated_at: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: Sequelize.NOW,
      },
      deleted_at: {
        type: Sequelize.DATE,
        allowNull: true,
      },
    });

    // 添加索引
    await queryInterface.addIndex('users', ['username']);
    await queryInterface.addIndex('users', ['email']);
  },

  down: async (queryInterface, Sequelize) => {
    await queryInterface.dropTable('users');
  },
};
